﻿using DocumentFormat.OpenXml.Lite.Helper;
using DocumentFormat.OpenXml.Lite.WordprocessingML.Word.Types;
using DocumentFormat.OpenXml.Lite.Xml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace DocumentFormat.OpenXml.Lite.WordprocessingML.Word.Table.Properties
{
    [XmlRoot("tblpPr", Namespace = Constants.WordMain)]
    public class TablePosition : XmlSerializable, ITablePropElement
    {
        /// <summary>
        /// Distance From Left of Table to Text
        /// </summary>
        [Optional]
        [XmlAttribute("leftFromText", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<uint> LeftDistance { get; set; }

        /// <summary>
        /// Distance From Right of Table to Text
        /// </summary>
        [Optional]
        [XmlAttribute("rightFromText", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<uint> RightDistance { get; set; }

        /// <summary>
        /// Distance Top Right of Table to Text
        /// </summary>
        [Optional]
        [XmlAttribute("topFromText", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<uint> TopDistance { get; set; }

        /// <summary>
        /// Distance From Bottom of Table to Text
        /// </summary>
        [Optional]
        [XmlAttribute("bottomFromText", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<uint> BottomDistance { get; set; }

        [Optional]
        [XmlAttribute("vertAnchor", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<ST_VAnchor> VerticalAnchor { get; set; }

        [Optional]
        [XmlAttribute("horzAnchor", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<ST_HAnchor> HorizontalAnchor { get; set; }

        /// <summary>
        /// Relative Horizontal Alignment From Anchor
        /// </summary>
        [Optional]
        [XmlAttribute("tblpXSpec", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<ST_XAlign> RelativeHAlignment { get; set; }

        /// <summary>
        /// Absolute Horizontal Alignment From Anchor
        /// </summary>
        [Optional]
        [XmlAttribute("tblpX", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<int> AbsoluteHAlignment { get; set; }

        /// <summary>
        /// Relative Vertical Alignment From Anchor
        /// </summary>
        [Optional]
        [XmlAttribute("tblpYSpec", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<ST_YAlign> RelativeVAlignment { get; set; }

        /// <summary>
        /// Absolute Vertical Alignment From Anchor
        /// </summary>
        [Optional]
        [XmlAttribute("tblpY", Namespace = Constants.WordMain, Form = XmlSchemaForm.Qualified)]
        public Nullable<int> AbsoluteVAlignment { get; set; }

        public TablePosition() { }

        public void Copy(object obj)
        {
            if (obj is TablePosition)
            {
                this.BottomDistance = (obj as TablePosition).BottomDistance;
                this.TopDistance = (obj as TablePosition).TopDistance;
                this.LeftDistance = (obj as TablePosition).LeftDistance;
                this.RightDistance = (obj as TablePosition).RightDistance;

                this.AbsoluteHAlignment = (obj as TablePosition).AbsoluteHAlignment;
                this.AbsoluteVAlignment = (obj as TablePosition).AbsoluteVAlignment;
                this.RelativeHAlignment = (obj as TablePosition).RelativeHAlignment;
                this.RelativeVAlignment = (obj as TablePosition).RelativeVAlignment;

                this.HorizontalAnchor = (obj as TablePosition).HorizontalAnchor;
                this.VerticalAnchor = (obj as TablePosition).VerticalAnchor;
            }
        }
    }
}
